# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ------------------------------
'''

yield:生成器
'''


def main(current):
    a = 0
    b = 1
    count = 0
    while count < current:
        yield a
        a, b = b, a+b
        count += 1
    return '---ok----'     # 如果生成器返回值需要用捕捉异常来接受


if __name__ == '__main__':
    #迭代多次
    # obj = main(5)
    # for i in obj:
    #     print(i)
    print('-' *50)
    # 迭代一次
    try:
        obj1 = main(1)
        i = next(obj1)
        print(i)
        i = next(obj1)
        print(i)

    except Exception as ret:
        print(ret.value)

        '''0
        ---ok----
        '''